//
//  MainViewController.m
//  微博5.18
//
//  Created by jyj on 16/5/21.
//  Copyright © 2016年 jyj. All rights reserved.
//

#import "MainViewController.h"
#import "DiscoverViewController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "ProfileViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //设置当前控制器的颜色
    self.tabBar.tintColor=[UIColor orangeColor];
    
    
    //添加子视图
    [self addChildViewContrillers];
}


-(void)addChildViewContrillers
{
    [self addChildViewController:@"HomeViewController" title:@"首页" imageName:@"tabbar_home"];
    [self addChildViewController:@"DiscoverViewController" title:@"发现" imageName:@"tabbar_discover"];
    
    
}


//分装
-(void)addChildViewController:(NSString *)vcName
                        title:(NSString *)title
                    imageName:(NSString *)imageName
{
    //根据类名创建对象
    UIViewController *vc=[[NSClassFromString(vcName)alloc]init];
    
    //设置其TabBar上的图标
    vc.tabBarItem.image=[UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage=[UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]];
    
    
    //将其嵌入一个导航栏控制器中
    UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:vc];
    
    vc.title=title;
    
    
    //将导航栏控制器添加到tabbar
    [self addChildViewController:navi];
    
}

@end
